package com.sihan.framework.etm.controller.business;

import com.framework.annotation.BusinessLog;
import com.framework.model.ApiResult;
import com.sihan.framework.etm.common.CommonBiz;
import com.sihan.framework.etm.dto.business.ToolOverviewDTO;
import com.sihan.framework.etm.service.business.StatisticalAnalysisService;
import com.sihan.framework.etm.vo.business.ToolOverviewVO;
import com.sihan.framework.etm.vo.statistics.BaseTypeVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author gyz
 * @version 1.0
 * @since jdk1.8
 */
@Api(tags = "统计分析")
@RestController
@RequestMapping("/bs/v0/statisticalAnalysis")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class StatisticalAnalysisController {

	private final StatisticalAnalysisService statisticalAnalysisService;
	
	private final CommonBiz commonBiz;
	
	@ApiOperation(value = "工器具总览", notes = "工器具总览", response = ToolOverviewVO.class)
	@GetMapping("/getToolOverview")
	@BusinessLog(value = "工器具总览")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
			@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true),
			@ApiImplicitParam(name = "toolCode", value = "RFID编号", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "deviceId", value = "智能柜编号", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "modelId", value = "型号", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "checkStartDate", value = "检验到期开始时间", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "checkEndDate", value = "检验到期结束时间", dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "status", value = "当前状态", dataType = "string", paramType = "query")
	})
	@RequiresPermissions("bs:tool:view")
	public ApiResult<?> getToolOverview(ToolOverviewDTO dto){
		return ApiResult.success(statisticalAnalysisService.getToolOverview(dto));
	}

	@ApiOperation(value = "工器具档案", notes = "工器具档案", response = Map.class)
	@GetMapping("/getToolDetailInfo")
	@BusinessLog(value = "工器具档案")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "toolId", value = "工器具Id", dataType = "string", paramType = "query",required = true)
	})
	public ApiResult<?> getToolDetailInfo(String toolId){
		return ApiResult.success(statisticalAnalysisService.getToolDetailInfo(toolId));
	}


	@ApiOperation(value = "智能柜可视化", notes = "智能柜可视化", response = Map.class)
	@GetMapping("/getDeviceInfoList")
	@BusinessLog(value = "智能柜可视化")
	@RequiresPermissions("bs:device:view")
	public ApiResult<?> getDeviceInfoList(){
		return ApiResult.success(statisticalAnalysisService.getDeviceInfoList());
	}

	@ApiOperation(value = "检验提醒数量统计", notes = "检验提醒数量统计", response = BaseTypeVO.class)
	@GetMapping("/getNeedCheckToolNum")
	@BusinessLog(value = "检验提醒数量统计")
	@RequiresAuthentication
	public ApiResult<?> getNeedCheckToolNum(){
		return ApiResult.success(statisticalAnalysisService.getNeedCheckToolNum());
	}

	@ApiOperation(value = "异常清单统计", notes = "异常清单统计", response = BaseTypeVO.class)
	@GetMapping("/getExceptionNum")
	@BusinessLog(value = "异常清单统计")
	@RequiresAuthentication
	public ApiResult<?> getExceptionNum(){
		return ApiResult.success(statisticalAnalysisService.getExceptionNum());
	}
	
	@ApiOperation(value = "自动处理异常数据", notes = "自动处理异常数据", response = ApiResult.class)
	@GetMapping("/handler_no_done_task")
	@BusinessLog(value = "自动处理异常数据")
	@RequiresAuthentication
	public ApiResult<?> handlerNoDoneTask(){
		//回到首页就清除缓存
		//CacheOperatorInfo.flushCashMap();
		//commonBiz.checkUndoneTask();
		return ApiResult.success();
	}

	//---------------------------------综合分析---------------------------------------

	@ApiOperation(value = "重要工器具统计", notes = "重要工器具统计", response= BaseTypeVO.class)
	@GetMapping("/importantTools")
	@BusinessLog(value = "重要工器具统计")
	@RequiresPermissions("bs:sumary:analysis")
	public ApiResult<?> importantTools(){
		return ApiResult.success(statisticalAnalysisService.selectImportantTool());
	}

	@ApiOperation(value = "工器具状态统揽", notes = "工器具状态统揽", response= BaseTypeVO.class)
	@GetMapping("/summaryTools")
	@BusinessLog(value = "工器具状态统揽")
	@RequiresPermissions("bs:sumary:analysis")
	public ApiResult<?> summaryTools(){
		return ApiResult.success(statisticalAnalysisService.selectSummaryTool());
	}

	@ApiOperation(value = "领用排行", notes = "领用排行", response= BaseTypeVO.class)
	@GetMapping("/borrowSort")
	@BusinessLog(value = "领用排行")
	@RequiresPermissions("bs:sumary:analysis")
	public ApiResult<?> borrowSort(){
		return ApiResult.success(statisticalAnalysisService.borrowSort());
	}

	@ApiOperation(value = "供货商排行", notes = "供货商排行", response= BaseTypeVO.class)
	@GetMapping("/manufactorSort")
	@BusinessLog(value = "供货商排行")
	@RequiresPermissions("bs:sumary:analysis")
	public ApiResult<?> manufactorSort(){
		return ApiResult.success(statisticalAnalysisService.manufatorSort());
	}

	@ApiOperation(value = "采购与报废统计", notes = "采购与报废统计", response= BaseTypeVO.class)
	@GetMapping("/purchaseAndScrap")
	@BusinessLog(value = "采购与报废统计")
	@RequiresPermissions("bs:sumary:analysis")
	public ApiResult<?> purchaseAndScrap(){
		return ApiResult.success(statisticalAnalysisService.statisPurchaseAndCrapt());
	}

	@ApiOperation(value = "领用与归还统计", notes = "领用与归还统计", response = BaseTypeVO.class)
	@GetMapping("/borrowAndReturn")
	@BusinessLog(value = "领用与归还统计")
	@RequiresPermissions("bs:sumary:analysis")
	public ApiResult<?> borrowAndReturn(){
		return ApiResult.success(statisticalAnalysisService.statisBorrowAndReturn());
	}

	@ApiOperation(value = "检验统计", notes = "检验统计", response = BaseTypeVO.class)
	@GetMapping("/inspect")
	@BusinessLog(value = "检验统计")
	@RequiresPermissions("bs:sumary:analysis")
	public ApiResult<?> inspect(){
		return ApiResult.success(statisticalAnalysisService.statisInpsectAndExpired());
	}

	@ApiOperation(value = "总量与配置量统计", notes = "总量与配置量统计", response = BaseTypeVO.class)
	@GetMapping("/totalAndConfig")
	@BusinessLog(value = "总量与配置量统计")
	@RequiresPermissions("bs:sumary:analysis")
	public ApiResult<?> totalAndConfig(){
		return ApiResult.success(statisticalAnalysisService.statisToolTotalAndConfig());
	}

}
